home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 8 / Eagles_Nest_Mac_Collection_Disc_8.TOAST / Developer Environments / AllegroCL11 / Examples / Sample-Modal-Dialog.Lisp < prev    next >
Encoding:
Text File  |  1987-10-27  |  4.3 KB  |  112 lines  |  [TEXT/CCL ]

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;sample-modal-dialog.lisp
  3. ;;
  4. ;;copyright 1987 Coral Software
  5. ;;
  6. ;;this file contains source-code for a sample modal dialog
  7. ;;
  8. ;;it runs in Allegro CL version 1.1
  9. ;;
  10.  
  11.  
  12.  
  13.  
  14. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15. ;;
  16. ;;create the dialog-object, specifying the window parameters
  17. ;;
  18. ;;  we don't want the window to be shown when it is created.  We just want to
  19. ;;  create it, so that we can later use it as a modal dialog
  20. ;;
  21.  
  22. (defvar *sample-modal-dialog* ())
  23.  
  24. (setq *sample-modal-dialog*
  25.       (oneof *dialog*
  26.              :window-type :double-edge-box
  27.              :window-size #@(250 95)
  28.              :window-position (make-point (ash (- *screen-width* 250) -1)
  29.                                           (+ *menubar-bottom* 20))
  30.              :window-show nil))
  31.  
  32. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  33. ;;
  34. ;;add some dialog-items to the modal dialog
  35. ;;
  36. ;;  The reason we don't do specify the items as argument to ONEOF is that we
  37. ;;  want to associate the items with instance variables in the dialog.
  38. ;;  To do this, we ask the dialog to HAVE the instance variables at the same
  39. ;;  time we create the items.  If this were done inside the call to ONEOF,
  40. ;;  the have would be executed in the wrong object [in the object current
  41. ;;  when ONEOF was called, rather than in the object created by ONEOF].
  42. ;;  The calling sequence used below takes advantage of the fact that HAVE
  43. ;;  returns its second argument.  For the purpose of ADD-DIALOG-ITEMS the
  44. ;;  HAVEs are transparent.  Yet the have the effect of binding instance
  45. ;;  variables to the newly created items.
  46. ;;
  47. ;;  Because the items are bound to instance variables in the dialog, they
  48. ;;  can be easily referenced.
  49. ;;
  50.  
  51. (ask *sample-modal-dialog*
  52.   (add-dialog-items
  53.    (have 'my-text
  54.          (oneof *editable-text-dialog-item*
  55.                 :dialog-item-text "Enter Expression Here"
  56.                 :dialog-item-size #@(225 16)
  57.                 :dialog-item-position #@(4 4)))
  58.    (have 'return-string-button
  59.          (oneof *radio-button-dialog-item*
  60.                 :dialog-item-text "Return As String"
  61.                 :dialog-item-position #@(4 30)
  62.                 :radio-button-cluster :return-choice
  63.                 :radio-button-pushed-p t))
  64.    (have 'return-read-button
  65.          (oneof *radio-button-dialog-item*
  66.                 :dialog-item-text "Read And Return"
  67.                 :dialog-item-position #@(4 52)
  68.                 :radio-button-cluster :return-choice))
  69.    (have 'return-eval-result
  70.          (oneof *radio-button-dialog-item*
  71.                 :dialog-item-text "Eval Input"
  72.                 :dialog-item-position #@(4 76)
  73.                 :radio-button-cluster :return-choice))
  74.    (have 'ok-button
  75.          (oneof *button-dialog-item*
  76.                 :dialog-item-text "OK"
  77.                 :dialog-item-size #@(55 16)
  78.                 :dialog-item-position #@(170 35)
  79.                 :dialog-item-action
  80.                 #'(lambda ()
  81.                     (return-from-modal-dialog
  82.                      (ask my-dialog
  83.                        (let* ((choice
  84.                                (pushed-radio-button :return-choice))
  85.                               (my-string
  86.                                (ask my-text (dialog-item-text))))
  87.                          (cond
  88.                           ((eq choice return-string-button)
  89.                            my-string)
  90.                           ((eq choice return-read-button)
  91.                            (read-from-string my-string))
  92.                           ((eq choice return-eval-result)
  93.                            (eval (read-from-string my-string))))))))))
  94.    (have 'cancel-button
  95.          (oneof *button-dialog-item*
  96.                 :dialog-item-text "Cancel"
  97.                 :dialog-item-size #@(55 16)
  98.                 :dialog-item-position #@(170 62)
  99.                 :dialog-item-action
  100.                 #'(lambda () (return-from-modal-dialog :cancel))))))
  101.  
  102.  
  103. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  104. ;;a sample call.
  105. ;;
  106. ;;  we pass MODAL-DIALOG a second argument of NIL so that it doesn't close
  107. ;;  the window upon return [it just hides the window].  In this manner, we
  108. ;;  can re-use the dialog many times without rebuilding [we just keep passing
  109. ;;  it it to MODAL-DIALOG].
  110. ;;
  111.  
  112. (modal-dialog *sample-modal-dialog* nil)